import { createStore, createLogger } from 'vuex'
import { storage } from '@/utils/utils'
import { TOKEN } from '@/assets/js/config.js'
const debug = import.meta.env.NODE_ENV !== 'production'
const stateDefault = {
  profile: null,
  token: ''
}
export const store = createStore({
  state: {
    profile: null,
    token: storage.get(TOKEN),
    isAPP: null,
    versionApp: '',
    platformApp: '',
    releaseWork: 0,
    bellDisposition: {
      time: 6
    },
    messageNum: {}
  },
  mutations: {
    resetState (state) {
      // 重置所有数据
      state = stateDefault
    },
    setProfile (state, data) {
      state.profile = data
    },
    setToken (state, data) {
      state.token = data
    },
    setApp (state, data) {
      state.isAPP = data
    },
    setPlatformApp (state, data) {
      state.platformApp = data
    },
    setVersionApp (state, data) {
      state.versionApp = data
    },
    setReleaseWork (state, data) {
      state.releaseWork = data
    },
    setBellDisposition (state, data) {
      state.bellDisposition = data
    },
    setMessageNum (state, data) {
      state.messageNum = data
    }
  },
  strict: debug,
  plugins: debug ? [createLogger()] : []
})

export function useStore () {
  return store
}

export default store
